package app

import (
	"fmt"
	"os"
	"os/signal"
	"simple_game/app/consts"
	"simple_game/app/http"
	"simple_game/app/libs/factory"
	"simple_game/app/libs/logger"
	"simple_game/app/libs/pprof"
	"simple_game/app/register"
	"simple_game/app/server"
	"simple_game/app/server/actor"
	"simple_game/app/utils"
	"syscall"
)

func Start(_ ...string) {
	sigChan := make(chan os.Signal, 1)
	signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
	logger.Start()
	fmt.Print(consts.PrintStart)
	// 路由注册
	register.RegisteredRoute()
	factory.Init()

	utils.MysqlStart()
	utils.RedisStart()
	go server.StartGRPC()
	go http.StartHttp()
	go server.Start()
	// 初始化actor
	actor.Init()
	// 性能分析
	pprof.StartPprof()

	<-sigChan
	Stop()
}

func Stop() {
	fmt.Println("simple game stop  start save")
	// todo 改成用chan
	actor.SaveAllActor()
}
